﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;

namespace PencasUruguayo.Models
{
    public class AccesoADatos
    {
        public bool LoguearUsuario(string username, string password)
        {
            bool loginCorrecto = false;
            try
            {
                Database db = DatabaseFactory.CreateDatabase("PencasUruguayo");
                DbCommand cmd = db.GetStoredProcCommand("LoguearUsuario");
                db.AddInParameter(cmd, "@username", DbType.String, username);
                db.AddInParameter(cmd, "@password", DbType.String, password);
                db.AddOutParameter(cmd, "@loginCorrecto", DbType.Boolean, 100);
                db.ExecuteNonQuery(cmd);

                loginCorrecto = Convert.ToBoolean(db.GetParameterValue(cmd, "@loginCorrecto"));

                return loginCorrecto;
            }
            catch (Exception e)
            {
                throw (e);
            }
        }
    }
}